import { defineStore } from 'pinia'
import { ref } from 'vue'
import storage from 'storejs'

export const useLoginStore = defineStore('loginStore', () => {
  const state = ref({
    token: storage.get('companytoken') || '', // 登录时的token
    account:storage.get('platformName') || '' //登录的用户名
  })

  const setToken = (payload) => {
    state.value.token = payload
    storage.set('companytoken', payload)
  }

  const setAccount = (payload) => {
    state.value.account = payload
    storage.set('platformName', payload)
  }

  return {
    state,
    setToken,
    setAccount,
  }
})
